<template>
  <van-action-sheet v-model:show="props.isShowSheet" title="使用地图打开" :actions="sheetList" cancel-text="取消" @close="onCancel" @cancel="onCancel"
    description="如果点击无响应，可能是您还没有安装该APP" close-on-click-action @select="handleSheetSelect" />
</template>

<script setup>
import { ref, onMounted } from 'vue'
import wx from 'weixin-js-sdk'
const sheetList = ref([
  // { name: '百度地图', id: 'baidu' },
  // { name: '腾讯地图', id: 'tencent' },
  // { name: '高德地图', id: 'gaode' },
  { name: '打开地图', id: 'miniProgram' },
])
const props = defineProps({
  isShowSheet: {
    type: Boolean,
    default: false,
  },
  selectedPoint: {
    type: Object,
    default: {},
  },
});
const emits = defineEmits(['close']);

// 打开导航菜单
const handleSheetSelect = (action) => {
  navToMap(props.selectedPoint.longitude, props.selectedPoint.latitude, props.selectedPoint.sitename, action.id)
}
const navToMap = (longitude = 0,  latitude= 0, name = '目的地', type = 1) => {
  // let url = ""
  // switch (type) {
  //   case 'baidu':
  //     // const appId = '115633671';
  //     url = `https://api.map.baidu.com/marker?location=${latitude},${longitude}&title=${name}&content=${name}&output=html`;
  //     // url = `baidumap://map/marker?location=${latitude},${longitude}&title=${title}&content=${content}&src=${appId}`;
  //     break;
  //   case 'tencent':
  //     url = `https://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};addr:${name}`;
  //     break;
  //   case 'gaode':
  //     url = `https://uri.amap.com/marker?position=${latitude},${longitude}&name=${name}&src=mypage&coordinate=gaode&callnative=1`

  // }

  wx.miniProgram.navigateTo({
    // url: `/pages/jump-xcx/jump-xcx?latitude=${latitude}&longitude=${longitude}&name=${name}&address=''`,
    url:`/pages/toMap/toMap?latitude=${latitude}&longitude=${longitude}&name=${name}`
  })
  // if (type == 1) {

  // } else if (type == 2) {
  //   // 其他地图的URL
  // }
  // window.location.href = url
}

// 关闭导航
const onCancel = () => {
  emits("close");
}
</script>